package sge.data;

import java.util.ArrayList;
import java.util.List;

import javax.jdo.PersistenceManager;
import javax.jdo.Query;

import sge.beans.Disciplina;

public class DisciplinaDAO {

	private static DisciplinaDAO dao;

	private DisciplinaDAO() {
	}

	public static DisciplinaDAO obterDisciplinaDAO() {
		if (dao == null) {
			dao = new DisciplinaDAO();
		}
		return dao;
	}

	public void inserirDisciplina(Disciplina disciplina) {
		PersistenceManager pm = PMF.get().getPersistenceManager();
		try {
			pm.makePersistent(disciplina);
		} finally {
			pm.close();
		}
	}

	@SuppressWarnings("unchecked")
	public List<Disciplina> todasDisciplinas() {
		List<Disciplina> lista = new ArrayList<Disciplina>();
		PersistenceManager pm = PMF.get().getPersistenceManager();
		try {
			Query query = pm.newQuery(Disciplina.class);
			lista.addAll((List<Disciplina>) query.execute());
		} finally {
			pm.close();
		}
		return lista;
	}
}
